import matplotlib.pyplot as plt
import matplotlib.dates as mdates
from datetime import datetime

# Data from the weather forecast
dates = ["2025-07-02", "2025-07-03", "2025-07-04", "2025-07-05", "2025-07-06", "2025-07-07", "2025-07-08"]
max_temps = [31, 32, 33, 32, 31, 31, 31]
min_temps = [24, 25, 24, 23, 23, 23, 23]

# Convert string dates to datetime objects
dates = [datetime.strptime(date, "%Y-%m-%d") for date in dates]

# Plotting
plt.figure(figsize=(10, 5))
plt.plot(dates, max_temps, label="最高气温", marker='o')
plt.plot(dates, min_temps, label="最低气温", marker='o')

# Formatting the plot
plt.gca().xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d'))
plt.gca().xaxis.set_major_locator(mdates.DayLocator())
plt.gcf().autofmt_xdate() # Rotation
plt.xlabel("日期")
plt.ylabel("气温 (°C)")
plt.title("北京未来七天气温预报")
plt.legend()
plt.grid(True)

# Show the plot
plt.show()